home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1997 December / PC Pro December 1997 CD-Rom coverdisc.iso / symantec / dbAnywh / JAVA.BIN / CLASSES.ZIP / sun / tools / zip / ZipReader.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-12-14  |  2.0 KB  |  86 lines

  1. package sun.tools.zip;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5.  
  6. public class ZipReader implements ZipConstants {
  7.    // $FF: renamed from: is java.io.InputStream
  8.    private InputStream field_0;
  9.    // $FF: renamed from: ze sun.tools.zip.ZipEntry
  10.    private ZipEntry field_1;
  11.    private ZipReaderInputStream zis;
  12.    private byte[] lochdr = new byte[30];
  13.  
  14.    public ZipReader(InputStream var1) {
  15.       this.field_0 = var1;
  16.    }
  17.  
  18.    public boolean nextEntry() throws ZipFormatException, IOException {
  19.       if (this.field_0 == null) {
  20.          return false;
  21.       } else {
  22.          if (this.zis != null) {
  23.             while(this.zis.count > 0) {
  24.                this.zis.skip((long)this.zis.count);
  25.             }
  26.          }
  27.  
  28.          this.readFully(this.lochdr, 0, 4);
  29.          if (!ZipFile.checkSig(this.lochdr, ZipConstants.LOCSIG)) {
  30.             if (ZipFile.checkSig(this.lochdr, ZipConstants.CENSIG)) {
  31.                return false;
  32.             } else {
  33.                this.field_0 = null;
  34.                throw new ZipFormatException("Invalid LOC header signature");
  35.             }
  36.          } else {
  37.             this.readFully(this.lochdr, 4, 26);
  38.             if (ZipFile.getWord(this.lochdr, 8) != 0) {
  39.                throw new ZipFormatException("Compressed entries not supported");
  40.             } else if ((ZipFile.getWord(this.lochdr, 6) & 1) == 1) {
  41.                throw new ZipFormatException("Encrypted entries not supported");
  42.             } else {
  43.                byte[] var1 = new byte[ZipFile.getWord(this.lochdr, 26)];
  44.                this.readFully(var1, 0, var1.length);
  45.                String var2 = new String(var1, 0, 0, var1.length);
  46.                this.field_1 = new ZipEntry(var2);
  47.                this.field_1.length = ZipFile.getLong(this.lochdr, 22);
  48.                this.field_1.mtime = ZipFile.getLong(this.lochdr, 12);
  49.                if (!this.skip((long)ZipFile.getWord(this.lochdr, 28))) {
  50.                   throw new ZipFormatException("Unexpected EOF");
  51.                } else {
  52.                   this.zis = new ZipReaderInputStream(this.field_0, this.field_1);
  53.                   return true;
  54.                }
  55.             }
  56.          }
  57.       }
  58.    }
  59.  
  60.    public ZipEntry getEntry() {
  61.       return this.field_1;
  62.    }
  63.  
  64.    public InputStream getInputStream() {
  65.       return this.zis;
  66.    }
  67.  
  68.    private boolean readFully(byte[] var1, int var2, int var3) throws IOException {
  69.       while(var3 > 0) {
  70.          int var4 = this.field_0.read(var1, var2, var3);
  71.          if (var4 == -1) {
  72.             return false;
  73.          }
  74.  
  75.          var2 += var4;
  76.          var3 -= var4;
  77.       }
  78.  
  79.       return true;
  80.    }
  81.  
  82.    private boolean skip(long var1) throws IOException {
  83.       return this.field_0.skip(var1) == var1;
  84.    }
  85. }
  86.